//
//  MineTopView.m
//  ZhiHuiLiJiang
//
//  Created by Work on 2018/11/18.
//  Copyright © 2018年 王雅鹏. All rights reserved.
//我的头部View

#import "MineTopView.h"

@interface MineTopView()

@end
@implementation MineTopView
- (instancetype)initWithFrame:(CGRect)frame{
    if (self == [super initWithFrame:frame]) {
        [self initAddSubViews];
        self.userInteractionEnabled = YES;
    }
    return self;
}
- (void)initAddSubViews{
    [self addSubview:self.settingBtn];
    [self addSubview:self.heardImaegView];
    [self addSubview:self.nameLabel];
    //个人中心按钮
    _userCentBtn = [BYVS createBtnBGColor:[UIColor clearColor] title:@"个人中心" titleColor:BYColor9 addSubView:self];
    _userCentBtn.titleLabel.font = BYPTBoldFont36;
    [_userCentBtn addTarget:self action:@selector(userCentBtnClick) forControlEvents:UIControlEventTouchUpInside];
    
    [self addSubViewFrames];
}
- (void)addSubViewFrames{
    BY_kWeakSelf(ws);
    //个人中心按钮
    [_userCentBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(ws.mas_left).offset(BY_Width(24));
        make.top.equalTo(ws.mas_top).offset(BY_Height(26)+ 20);//
    }];
    [self.settingBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo (ws.mas_right).offset(BY_Width(-24));
        make.centerY.equalTo(ws.userCentBtn.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(BY_Width(52),BY_Width(52)));
    }];
    [self.heardImaegView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo (ws.mas_top).offset(BY_Height(116)+20);
        make.size.mas_equalTo(CGSizeMake(BY_Width(224),BY_Width(224)));
        make.centerX.equalTo(ws.mas_centerX);
    }];
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo (ws.heardImaegView.mas_bottom).with.offset(BY_Height(20));
        make.centerX.equalTo(ws.mas_centerX);
        make.bottom.equalTo (ws.mas_bottom).offset(BY_Height(-16));
    }];
}
- (UIButton *)settingBtn{
    if (!_settingBtn) {
        _settingBtn =[UIButton buttonWithType:UIButtonTypeCustom];
        [_settingBtn setImage:[UIImage imageNamed:@"mineIcon_setting"] forState:UIControlStateNormal];
        [_settingBtn addTarget:self action:@selector(settingBtnClick) forControlEvents:UIControlEventTouchUpInside];
    }
    return _settingBtn;
}
- (UIImageView *)heardImaegView{
    if (!_heardImaegView) {
        _heardImaegView = [[UIImageView alloc]init];
        _heardImaegView.backgroundColor = [UIColor whiteColor];
        _heardImaegView.image = [UIImage imageNamed:@"mineIcon_HeadIcon"];
        _heardImaegView.userInteractionEnabled = YES;
        _heardImaegView.layer.cornerRadius = BY_Width(224)/2.0;
        _heardImaegView.layer.masksToBounds = YES;
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(heardImageViewClick)];
        [_heardImaegView addGestureRecognizer:tap];
    }
    return _heardImaegView;
}
- (UILabel *)nameLabel{
    if (!_nameLabel) {
        _nameLabel = [[UILabel alloc]init];
        _nameLabel.text = @"登陆注册";
        _nameLabel.font = BYPTBoldFont36;
        _nameLabel.textColor = BYColor9;
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(heardImageViewClick)];
        [_nameLabel addGestureRecognizer:tap];
    }
    return _nameLabel;
}

#pragma mark- 用户交互
- (void)userCentBtnClick{
    if (self.clickUserCentBtn) {
        self.clickUserCentBtn();
    }
}
- (void)settingBtnClick{
    if (self.clickSettingBtn) {
        self.clickSettingBtn();
    }
}
- (void)heardImageViewClick{
    if (self.clickHeardImgLogin) {
        self.clickHeardImgLogin();
    }
}


@end
